package models;

import play.*;
import play.data.validation.Required;
import play.db.jpa.*;

import javax.persistence.*;
import java.util.*;

/**
 * 商品实体，存放固有属性
 * 关于价格：
 * 1.进货价改变的话，另建实体
 * 2.销售价／会员价不在此实体保存，价格与特定的用户组／用户关联 
 * 
 * @see models.PricedCommodity
 * 
 * @author justin
 *
 */
@Entity
public class Commodity extends BaseEntity {

	/*大图*/
	@OneToMany(mappedBy="commodity", cascade=CascadeType.ALL)
	public List<CommodityImage> images;
	
	@Required
	@ManyToOne
	public Brand brand;
 
	/*商品名称*/
	@Required
	public String name;
	
	/*商品编号*/
	@Required
	public String SN;
	
	/*厂家商品编号*/
	public String manufacturerSN;
	
	/*商品单位*/
	public String unit;
	
	/*商品尺寸*/
	public String size;
	
	/*材质*/
	public String material;
	
	/*重量*/
	@Required
	public double weight;
	
	/*产地*/
	public String placeOfOrigin;
	
	/*包装*/
	public String packaging;
	
	/*装箱数量*/
	public int numberPerBox;
	
	/*毛重*/
	public String grossWeight;
	
	/*净重*/
	public String netWeight;
	
	/*剩余数量*/
	public long quantityLeft;
	
	/*成本价格*/
	@Required
	public double cost;
	
	/*商品描述，存放HTML代码*/
	@Lob
	public String description;
	
	/*价格，不存到数据库，映射到当前用户的标价*/
	@Transient
	public double price;
	
	public enum OnSaleStatus{
		ONSALE_LIMITED, ONSALE_UNLIMITED, OFFSALE;
		/*有限数量商品， 无限数量商品， 商品下架了*/
		public String value = name();
	}
	
	public OnSaleStatus onSaleStatus;
	
	public enum ChangeQuantityWay{
		SET_TO, ADD, MINUS;
		/*有限数量商品， 无限数量商品， 商品下架了*/
		public String value = name();
	}
}
